from pyson.gen import PysonObject, string, number, date, boolean, array, struct, PysonObjectMeta

class Component(PysonObject):
    otype = string()
    id = string()

    def __init__(self, objectType):
        self.otype = objectType

class Field(Component):
    name = string()
    label = string()
    clazz = string()

    def __init__(self, otype, fieldName, valueClass):
        self.__super.__init__(otype)
        self.name = fieldName
        self.label = fieldName
        self.clazz = valueClass

class StringField(Field):
    value = string()

    def __init__(self, fieldName, value):
        self.__super.__init__("StringField", fieldName, "java.lang.String")
        if value is not None:
            self.value = value


class BooleanField(Field):
    value = boolean()

    def __init__(self, fieldName, value):
        self.__super.__init__("BooleanField", fieldName, "java.lang.Boolean")
        if value is not None:
            self.value = value

class NumberField(Field):
    decimalPrecision = number()
    value = number()

    def __init__(self, fieldName, numberClass, value):
        self.__super.__init__("NumberField", fieldName, numberClass)
        if value is not None:
            self.value = value

        if numberClass == "java.lang.Byte" \
        or numberClass == "java.lang.Short" \
        or numberClass == "java.lang.Integer" \
        or numberClass == "java.lang.Long":
            self.decimalPrecision = 0
        elif numberClass == "java.lang.Float":
            self.decimalPrecision = 7
        elif numberClass == "java.lang.Double":
            self.decimalPrecision = 60
        else:
            self.decimalPrecision = 0

class DateField(Field):
    value = date()

    def __init__(self, fieldName, value):
        self.__super.__init__("DateField", fieldName, "java.util.Date")
        if value is not None:
            self.value = value

class ArrayField(Field):
    value = array(string)

    def __init__(self, fieldName, value):
        self.__super.__init__("ArrayField", fieldName, "java.lang.Array")
        if value is not None:
            self.value = value


class AbstractItem(Component):
    text = string()

    def __init__(self, itemId, txt, otype):
        self.__super.__init__(otype)
        self.text = txt
        self.id = itemId

class Item(AbstractItem):
    def __init__(self, itemId, txt):
        self.__super.__init__(itemId, txt, "Item")


class CheckItem(AbstractItem):
    checked = boolean()

    def __init__(self, itemId, txt):
        self.__super.__init__(itemId, txt, "CheckItem")


class ProjectEntry(PysonObject):
    id = string()
    entryType = string()
    #extensions = struct()
    extensions = array(struct)

    def __init__(self, entryId, entryType, exts):
        self.id = entryId
        self.entryType = entryType
        self.extensions = exts
#        extBuildersDict = {}
#        for extBuilder in exts:
#            extBuildersDict[extBuilder.id] = struct(extBuilder)
#
#        dynExtBuilderCls = PysonObjectMeta("DynamicExtEntriesBuilder", (PysonObject,), extBuildersDict)
#
#        self.extensions = dynExtBuilderCls()